//This program is designed to ask for the gas consumption in miles/gallons.
//converts the information to kilometers/gallons then displays the result.
#include<iostream.h>
// Free function declalration
float convert(float consumption);
int main ()
{
float gas_consumption_MperG;
cout<<"Enter the gas consumption in Miles/Gallons: ";
cin>>gas_consumption_MperG;
//Converting Miles/gal to Km/lit.
//Then inverting Km/l to lit/Km.
//If X litres is consumed in 1 Km, then 100*X Litres is consumed per 100 Km.
cout<<endl<<"The gas consumption for "<<gas_consumption_MperG<< " Miles/gallons"
" is equivalent to "<<convert(gas_consumption_MperG)<<'\n'<<"Litres"
"/100 Kilometers"<<endl<<endl;
return 0;
}
// Free function Implementation
float convert(float consumption)
{
return 100/(consumption*0.4227213);
}
//Run:
/*
Enter the gas consumption in Miles/Gallons: 34
The gas consumption for 34 Miles/gallons is equivalent to 6.95772
Litres/100 Kilometers
Press any key to continue
*/
|